<?php


namespace app\agent\Controller;


use think\Controller;
use think\Db;
use think\Session;

class Login extends Controller
{
    public function check_user()
    {
        $data = $this->request->post();
        if ($data) {
            $res = Db::table('admin')
                ->where([
                    'username' => $data['username'],
                    'password' => md5($data['password']),
                    'role_id'  => 1
                ])->find();
            if ($res) {
                Session::set('agent.id', $res['id']);
                Session::set('agent.username', $res['username']);
                if (Session::get('agent')) {
                    return json(['msg' => '登录成功', 'code' => 0]);
                } else {
                    return json(['msg' => '登录失败', 'code' => 1]);
                }
            } else {
                return json(['msg' => '用户名或者密码错误!', 'code' => 1]);
            }
        }
    }
}